package cn.legend.travel.admin.authorize.dao.persist.repository.impl;

import cn.legend.travel.admin.authorize.dao.persist.mapper.RoleFrontendMenuMapper;
import cn.legend.travel.admin.authorize.dao.persist.repository.IRoleFrontendMenuRepository;
import cn.legend.travel.admin.authorize.pojo.entity.RoleFrontendMenu;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class RoleFrontendMenuRepositoryImpl implements IRoleFrontendMenuRepository {
    private final RoleFrontendMenuMapper mapper;


    @Override
    public int insert(Long roleId, Long menuId) {
        RoleFrontendMenu roleFrontendMenu = new RoleFrontendMenu();
        roleFrontendMenu.setRoleId(roleId);
        roleFrontendMenu.setFrontendMenuId(menuId);
        return mapper.insert(roleFrontendMenu);
    }

    @Override
    public int deleteByRoleAndMenu(Long roleId, Long menuId) {
        QueryWrapper<RoleFrontendMenu> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id", roleId);
        wrapper.eq("frontend_menu_id", menuId);
        return mapper.delete(wrapper);
    }

    @Override
    public RoleFrontendMenu getByMenuId(Long roleId, Long menuId) {
        QueryWrapper<RoleFrontendMenu> wrapper = new QueryWrapper<>();
        wrapper.eq("role_id", roleId);
        wrapper.eq("frontend_menu_id", menuId);
        return mapper.selectOne(wrapper);
    }

}
